package com.hsoft.zhxy.app.xtgl_02_01.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hsoft.zhxy.app.common.model.entity.JcqxBm;
import com.hsoft.zhxy.app.xtgl_02_01.model.query.BmxxQUERY;
import com.hsoft.zhxy.app.xtgl_02_01.model.vo.BmtreeVO;
import com.hsoft.zhxy.app.xtgl_02_01.model.vo.YhbmxxVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * All rights Reserved, Designed By 哈尔滨工业大学软件工程股份有限公司
 * 
 * @Title: 部门 DAO层接口
 * @Package 
 * @Description: 
 * @author: system
 * @date: 2020-10-23
 */
@Mapper
@Repository
public interface JcqxBmMapper extends BaseMapper<JcqxBm> {
 @Select("<script> " +
         "   select" +
         " bmm,bmmc,fbmm,pxh,sfejbm " +
         " from jcqx_bm " +
         "${ew.customSqlSegment}" +
         "order by pxh"    +
         "</script>")
 List<BmtreeVO> selecBmtList(@Param("ew") QueryWrapper <JcqxBm> queryWrapper);

 @Select("<script> " +
         "   select" +
         " bmm,bmmc,fbmm,sfejbm,pxh " +
         " from jcqx_bm " +
         "${ew.customSqlSegment}" +
         "</script>")
 IPage<JcqxBm> selectBmListByPageFbmm(Page<JcqxBm> pageObj, @Param("ew") QueryWrapper<BmxxQUERY> queryWrapper);

 @Select("<script> " +
         "select b.id,a.yhid,c.bmm,a.xm,c.bmmc,a.yhzt,a.sjh,a.dzyx,b.sfzz," +
         "a.cjsj," +
         "a.bgsj " +
         " from jcqx_yh a" +
         " LEFT JOIN jcqx_yhbm b ON a.yhid=b.yhid" +
         " LEFT JOIN jcqx_bm c ON b.bmm=c.bmm" +
         " ${ew.customSqlSegment}" +
         "</script>")

 IPage<YhbmxxVO> findYhListByPageBmm(Page<YhbmxxVO> pageObj, @Param("ew") QueryWrapper<BmxxQUERY> queryWrapper);

 @Select("<script> " +
         "delete from jcqx_bm " +
         " ${ew.customSqlSegment}" +
         "</script>")
 Integer deleteBatch(@Param("ew") QueryWrapper<List<String>> queryWrapper);

 @Select("<script> " +
         "select a.yhid,c.bmm,a.xm,c.bmmc,a.yhzt,a.sjh,a.dzyx,b.sfzz," +
         "a.cjsj," +
         "a.bgsj " +
         " from jcqx_yh a" +
         " LEFT JOIN jcqx_yhbm b ON a.yhid=b.yhid" +
         " LEFT JOIN jcqx_bm c ON b.bmm=c.bmm" +
         " ${ew.customSqlSegment}" +
         "</script>")
 List<YhbmxxVO> findYhListByBmm(@Param("ew") QueryWrapper<JcqxBm> queryWrapper);

 @Select("<script> " +
         "update jcqx_yhbm set sfzz=0 " +
         " ${ew.customSqlSegment}" +
         "</script>")
 Integer updateYhbmzt(@Param("ew")QueryWrapper updateQueryWrapper);

 @Select("<script> " +
         "select id,yhid,bmm from  jcqx_yhbm  " +
         " ${ew.customSqlSegment}" +
         "</script>")
 List<YhbmxxVO> findYhListByYhidBmm(@Param("ew")QueryWrapper<JcqxBm> yhbmQueryWrapper);
 @Select("<script> " +
         "update jcqx_yhbm set sfzz=#{sfzz} " +
         " ${ew.customSqlSegment}" +
         "</script>")
 Integer updateYhbmBatch(@Param("sfzz")int sfzzdr, @Param("ew")QueryWrapper updateQueryWrapper);
 @Select("<script> " +
         "begin" +
         " <foreach collection='yh' item='item' open='' separator='' close=''> " +
         " insert into jcqx_yhbm (id,yhid,bmm,sfzz,cjr,cjsj,bgr,bgsj)" +
         "  values (#{item.id},#{item.yhid},#{bmm},#{sfzz},'sys',sysdate,'sys',sysdate);" +
         "</foreach>" +
         " end;" +
         "</script>")
 Integer insertYhbmBatch(@Param("yh")List<YhbmxxVO> yh, @Param("sfzz")int sfzzdr,@Param("bmm") String bmm);
}